package servlet.Article;

import DAO.ArticleDAO;
import Model.Article;
import Model.User;
import appexception.AppException;
import service.BaseService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @program: wsn_blog
 * @description ：修改文章操作
 * @author:王松年
 * @creat: 2021-07-12 20:27:03
 **/

@WebServlet("/change")
public class ArticleChangeServlet extends BaseService {

    @Override
    protected void query(HttpServletRequest req, HttpServletResponse resp) throws SQLException, IOException {
        Article article = objectMapper.readValue(req.getInputStream(), Article.class);
        if (article.getTitle() == null || article.getTitle().length() == 0) {
            throw new AppException("ADD000", "请输入文章标题");
        }
        boolean flag = ArticleDAO.change(article);
        if (!flag) {
            throw new AppException("ADD001", "修改文章失败");
        }
    }
}